Skip to content

perf: replace /dev/urandom | tr with openssl rand to fix CPU spike in gen_random_string#3887

Merged
MHSanaei merged 1 commit intoMHSanaei:mainfrom
Kookiejarz:main
Apr 1, 2026
Merged

perf: replace /dev/urandom | tr with openssl rand to fix CPU spike in gen_random_string#3887
MHSanaei merged 1 commit intoMHSanaei:mainfrom
Kookiejarz:main

Conversation

@Kookiejarz
Copy link
Copy Markdown
Contributor

closes #3886

Replace /dev/urandom | tr pipeline with openssl rand -base64 to reduce
tr's byte rejection rate from ~75% to ~2%, fixing CPU spikes on low-spec VPS.

See issue #3886 for detailed analysis.

Copilot AI review requested due to automatic review settings March 5, 2026 03:26
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: b01a71f32d

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

This comment was marked as outdated.

@cherts
Copy link
Copy Markdown
Contributor

cherts commented Mar 5, 2026

Maybe it's worth using a simpler and lighter program - pwgen ?

@Kookiejarz
Copy link
Copy Markdown
Contributor Author

Maybe it's worth using a simpler and lighter program - pwgen ?

Thanks for the suggestion! pwgen is indeed a great and lightweight tool specifically designed for this purpose. :D

However, for a self-contained installation script, introducing pwgen would mean adding a highly specific, single-purpose dependency. While the PR does add openssl to the package manager lists, openssl is a ubiquitous core utility that is almost universally available across all distributions (including minimal ISOs and Alpine) - and also an implicit dependency via curl, which is required for the one-click installation.

Using openssl rand -base64 also provides cryptographically secure pseudo-randomness (CSPRNG) without adding additional single-use tools to the system, keeping it lightweight.

@MHSanaei
Copy link
Copy Markdown
Owner

MHSanaei commented Mar 8, 2026

Thanks for your PR
we have two more gen_random_string on x-ui.sh and update.sh

@Kookiejarz
Copy link
Copy Markdown
Contributor Author

Thanks for your PR we have two more gen_random_string on x-ui.sh and update.sh

Got it, already modified and commited. :)

@MHSanaei MHSanaei merged commit 169b216 into MHSanaei:main Apr 1, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

perf: gen_random_string causes high CPU usage due to 75% byte rejection in tr

4 participants